package com.puhui.education.util;

import java.io.File;

/**
 * Created by Administrator on 2016/6/21.
 */
public class CleanCacheUtil {
    public static long size = 0;

    public static long getCacheSize(File file) {
        if (file != null && file.exists() && file.isDirectory()) {
            File items[] = file.listFiles();
            if (items != null && items.length != 0) {
                for (int i = 0; i < items.length; i++) {
                    getCacheSize(items[i]);
                }
            }
        } else if (file != null && file.exists() && file.isFile() && file.length() != 0) {
            size += file.length();
        }
        return size;
    }

    public static void cleanCache(File file) {
        if (file != null && file.exists() && file.isDirectory()) {
            File items[] = file.listFiles();
            if (items != null && items.length != 0) {
                for (int i = 0; i < items.length; i++) {
                    cleanCache(items[i]);
                }
            }
        } else if (file != null && file.exists() && file.isFile() && file.length() != 0) {
            file.delete();
        }
    }
}
